/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_NET_TCP_TCP_WORKER_H_
#define NODE_NET_TCP_TCP_WORKER_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <event2/event.h>
#include "node/system/thread.h"

namespace node {
    namespace net {

        class TcpWorker : public ::node::system::Thread
        {
        public:
            TcpWorker(void);
            virtual ~TcpWorker(void);
            virtual void Stop(void);

            bool Start(void);

            struct event_base *AcquireBase(void) {
                ++load_;
                return ebase_;
            }

            void ReleaseBase(void) {
                --load_;
            }

            inline int get_load(void) const {
                return load_;
            }

        protected:
            virtual void Run(void);

        private:
            static void OnTimeout(evutil_socket_t, short, void *);

            struct event_base *ebase_;
            struct event *edummy_;
            volatile int load_;
        };

    }
}

#endif // NODE_NET_TCP_TCP_WORKER_H_
